package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.OrganizationSettlement;
import com.eling.elcms.travel.model.view.OrganizationSettlementView;
import com.eling.elcms.travel.service.IOrganizationSettlementManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Controller
public class OrganizationSettlementController extends BaseFormController{

	@Autowired
	private IOrganizationSettlementManager orgSettlementManager;
	
	@RequestMapping("/api/organizationsettlement/save")
	@ResponseBody
	public OrganizationSettlement save(@ModelAttribute@ModelFilling OrganizationSettlement cond){
		return orgSettlementManager.save(cond);
	}
	
	@RequestMapping("/api/organizationsettlement/{pkOrganizationSettlement}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkOrganizationSettlement){
		orgSettlementManager.remove(pkOrganizationSettlement);
		return new Msg("删除成功");
	}
	
	@RequestMapping("/api/organizationsettlement/query")
	@ResponseBody
	public List<OrganizationSettlement> query(@ModelAttribute OrganizationSettlement cond){
		return orgSettlementManager.query(cond);
	}
	
	@RequestMapping("/api/organizationsettlement/search*")
	@ResponseBody
	public List<OrganizationSettlement> search(@ModelAttribute SearchCondition sc,@ModelAttribute OrganizationSettlement cond){
		sc.setQueryCondition(cond);
		return orgSettlementManager.search(sc);
	}
	
	/** 机构预收/预付款 查询*/
	@RequestMapping("/api/organizationsettlement/querybyservice")
	@ResponseBody
	public List<OrganizationSettlementView> queryByService(@RequestParam(value="startDate")Date startDate,
							@RequestParam(value="endDate")Date endDate,
							@RequestParam(value="pkOrganization")Long pkOrganization){
		return orgSettlementManager.queryByService(startDate,endDate,pkOrganization);
	}
	
	/* 结算查询*/
	@RequestMapping("/api/organizationsettlement/queryByAccount")
	@ResponseBody
	public List<OrganizationSettlementView> queryByAccount(@RequestParam(value="pkOrganization")Long pkOrganization,
														   @RequestParam(value="status") String status ,
														   @RequestParam(value="startDate")Date  startDate,
														   @RequestParam(value="endDate")Date endDate){
		return orgSettlementManager.queryByAccount(pkOrganization,status,startDate,endDate);
	}
	
}
